package com.liangxy.news.model;

import androidx.room.Entity;
import androidx.room.PrimaryKey;
import androidx.annotation.NonNull;
import androidx.room.Ignore;

import java.io.Serializable;

/**
 * News entity for storing news data
 */
@Entity(tableName = "news")
public class News implements Serializable {
    
    @PrimaryKey
    @NonNull
    private String uniquekey;
    
    private String title;
    private String date;
    private String category;
    private String authorName;
    // API field names
    private String author_name;
    private String url;
    private String thumbnail;
    // API field names for thumbnails
    private String thumbnail_pic_s;
    private String thumbnail_pic_s02;
    private String thumbnail_pic_s03;
    private String content;
    private boolean is_content;
    
    // For local database use
    private boolean isFollowed;
    private long lastReadTime;
    // 新闻来源平台
    private String source;
    
    @Ignore
    public News() {
        // Required by Room
    }
    
    public News(@NonNull String uniquekey, String title, String date, String category, 
                String authorName, String url, String thumbnail, String content) {
        this.uniquekey = uniquekey;
        this.title = title;
        this.date = date;
        this.category = category;
        this.authorName = authorName;
        this.author_name = authorName;
        this.url = url;
        this.thumbnail = thumbnail;
        this.thumbnail_pic_s = thumbnail;
        this.content = content;
        this.is_content = content != null && !content.isEmpty();
    }
    
    @NonNull
    public String getUniquekey() {
        return uniquekey;
    }
    
    public void setUniquekey(@NonNull String uniquekey) {
        this.uniquekey = uniquekey;
    }
    
    public String getTitle() {
        return title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    public String getDate() {
        return date;
    }
    
    public void setDate(String date) {
        this.date = date;
    }
    
    public String getCategory() {
        return category;
    }
    
    public void setCategory(String category) {
        this.category = category;
    }
    
    public String getAuthorName() {
        return authorName != null ? authorName : author_name;
    }
    
    public void setAuthorName(String authorName) {
        this.authorName = authorName;
        this.author_name = authorName;
    }
    
    public String getAuthor_name() {
        return author_name;
    }
    
    public void setAuthor_name(String author_name) {
        this.author_name = author_name;
        this.authorName = author_name;
    }
    
    public String getUrl() {
        return url;
    }
    
    public void setUrl(String url) {
        this.url = url;
    }
    
    public String getThumbnail() {
        return thumbnail != null ? thumbnail : thumbnail_pic_s;
    }
    
    public void setThumbnail(String thumbnail) {
        this.thumbnail = thumbnail;
        this.thumbnail_pic_s = thumbnail;
    }
    
    public String getThumbnail_pic_s() {
        return thumbnail_pic_s;
    }
    
    public void setThumbnail_pic_s(String thumbnail_pic_s) {
        this.thumbnail_pic_s = thumbnail_pic_s;
        if (this.thumbnail == null) {
            this.thumbnail = thumbnail_pic_s;
        }
    }
    
    public String getThumbnail_pic_s02() {
        return thumbnail_pic_s02;
    }
    
    public void setThumbnail_pic_s02(String thumbnail_pic_s02) {
        this.thumbnail_pic_s02 = thumbnail_pic_s02;
    }
    
    public String getThumbnail_pic_s03() {
        return thumbnail_pic_s03;
    }
    
    public void setThumbnail_pic_s03(String thumbnail_pic_s03) {
        this.thumbnail_pic_s03 = thumbnail_pic_s03;
    }
    
    public String getContent() {
        return content;
    }
    
    public void setContent(String content) {
        this.content = content;
        this.is_content = content != null && !content.isEmpty();
    }
    
    public boolean isIs_content() {
        return is_content;
    }
    
    public void setIs_content(boolean is_content) {
        this.is_content = is_content;
    }
    
    public boolean isFollowed() {
        return isFollowed;
    }
    
    public void setFollowed(boolean followed) {
        isFollowed = followed;
    }
    
    public long getLastReadTime() {
        return lastReadTime;
    }
    
    public void setLastReadTime(long lastReadTime) {
        this.lastReadTime = lastReadTime;
    }
    
    public String getSource() {
        return source;
    }
    
    public void setSource(String source) {
        this.source = source;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        
        News news = (News) o;
        
        return uniquekey.equals(news.uniquekey);
    }
    
    @Override
    public int hashCode() {
        return uniquekey.hashCode();
    }
} 